﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using LotroTweeter.Engine;

namespace LotroTweeter.UnitTests.Engine.LotroDataAPI
{
    /// <summary>
    /// Summary description for LotroConnectorLinkedToLiveData
    /// </summary>
    [TestClass]
    public class LotroConnectorLinkedToLiveData
    {
        [TestMethod]
        public void ShouldRetrieveDawningEclipseRosterFromWindfola()
        {
            var connector = new LotroConnector();
            Assert.IsNotNull(connector);
            var result = connector.GetKinRoster("Dawning Eclipse");
            Assert.IsNotNull(result);

            var kinName = result.Element("guild").Attribute("name").Value;
            Assert.AreEqual("Dawning Eclipse",kinName);
            int membershipCount;
            Assert.IsTrue(int.TryParse(result.Element("guild").Attribute("memberCount").Value,out membershipCount));

            if (result != null)
            {
                var characterCount = (from r in result.Descendants("character")
                                      select r).Count();
                Assert.AreEqual(membershipCount, characterCount);
            }
            else
            {
                Assert.Fail();
            }
        }

        [TestMethod]
        public void ShouldRetrieveSilverleafCharacterDataFromWindfola()
        {
            var connector = new LotroConnector();
            Assert.IsNotNull(connector);
            var result = connector.GetCharacterData("Silverleaf");
            Assert.IsNotNull(result);

            var characterName = result.Element("character").Attribute("name").Value;
            Assert.AreEqual("Silverleaf",characterName);
            int currentLevel;
            Assert.IsTrue(int.TryParse(result.Element("character").Attribute("level").Value,out currentLevel));
        }
    }
}